package com.ce.cetag.tags.tab;

import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;

import com.ce.cetag.model.TabModel;


/**
 *
 *  功能描述：
 *
 * <p> 版权所有：中企动力</p>
 * <p> 未经本公司许可，不得以任何方式复制或使用本程序</p>
 * @author ��˧��贺帅彪
 * @create date : 2007-9-7
 */
public class TabTag extends BodyTagSupport {
	private String id;

	private String label;

	private String onClick;

	public void setOnClick(String onClick) {
		this.onClick = onClick;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	private Object getBodyContentString() throws JspException {
		Object result = null;
		if (getBodyContent() == null) {
			return null;
		}
		result = getBodyContent().getString();
		result = ExpressionEvaluatorManager.evaluate("result", result
				.toString(), Object.class, this, pageContext);

		return result;
	}

	@Override
	public int doStartTag() throws JspException {
		return EVAL_BODY_BUFFERED;
	}

	@Override
	public int doEndTag() throws JspException {
		TabStripTag tabStript = (TabStripTag) TagSupport.findAncestorWithClass(
				this, TabStripTag.class);
		List<TabModel> list = tabStript.getTabList();
		TabModel tabModel = new TabModel();
		tabModel.setId(id);
		tabModel.setLabel(label);
		tabModel.setContent(getBodyContentString());
		tabModel.setOnClick(onClick);
		list.add(tabModel);
		return EVAL_PAGE;
	}

}
